﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

using Htss.Platform.Data;
namespace DreamBox.DAL.Posts
{
    public class Posts
    {
        /// <summary>
        /// 更新赞次数
        /// </summary>
        /// <param name="PostsID"></param>
        /// <returns></returns>
        public bool UpdatePlus(int PostsID)
        {
            DbAction action = new DbAction();
            action.SetFields("PostsID", PostsID);
            return action.ExecuteSqlNonQuery("update dbox_Posts set Plus=Plus+1 where PostsID=@PostsID");
        }
        /// <summary>
        /// 更新属性鉴定
        /// </summary>
        /// <param name="PostsID"></param>
        /// <param name="PropertyID"></param>
        /// <returns></returns>
        public bool UpdateProperty(int PostsID, int PropertyID)
        {
            DbAction action = new DbAction("dbox_Posts");
            action.SetFields("PostsID", PostsID, DbFieldType.Condition);
            action.SetFields("Property", PropertyID);
            return action.Update();
        }
        /// <summary>
        /// 更新文字状态
        /// </summary>
        /// <param name="PostsID"></param>
        /// <param name="Locking"></param>
        /// <returns></returns>
        public bool UpdateStatus(int PostsID,bool IsStatus)
        {
            DbAction action = new DbAction("dbox_Posts");
            action.SetFields("PostsID", PostsID, DbFieldType.Condition);
            action.SetFields("IsStatus", IsStatus);
            return action.Update();
        }
        /// <summary>
        /// 更新浏览次数
        /// </summary>
        /// <param name="artid"></param>
        /// <returns></returns>
        public int UpdateClick(int PostsID)
        {
            PSelect ps = new PSelect();
            int click = int.Parse(ps.Select("dbox_Posts", "BrowseCount", "PostsID=" + PostsID).Rows[0]["BrowseCount"].ToString());
            DbAction action = new DbAction("dbox_Posts");
            action.SetFields("PostsID",PostsID,DbFieldType.Condition);
            action.SetFields("BrowseCount", (click + 1));
            action.Update();
            return (click + 1);
        }

        /// <summary>
        /// 删除文字
        /// </summary>
        /// <param name="artid"></param>
        /// <returns></returns>
        public GHashTable Delete(int PostsID,int UserID)
        {
            DbProc gProc = new DbProc("dbox_proc_DeletePosts");
            gProc.SetFields("@UserID",UserID);
            gProc.SetFields("@PostsID",PostsID);
            gProc.SetFields("@TipsMsg", "", SqlDbType.VarChar, 180, ParameterDirection.Output);
            gProc.SetFields("@returnValue", 0, SqlDbType.Int, 4, ParameterDirection.ReturnValue);
            return gProc.ExecNonQueryHashTable();
            //
        }
       
        /// <summary>
        /// 编辑文字
        /// </summary>
        /// <param name="m">实体对象</param>
        /// <returns></returns>
        public bool Update(DreamBox.Model.Posts m)
        {
            DbAction action = new DbAction("dbox_Posts");
            action.SetFields("PostsID", m.PostsID, DbFieldType.Condition);
            action.SetFields("Title", m.Title);
            action.SetFields("Contents", m.Contents);
            action.SetFields("KeyWords", m.KeyWords);
            action.SetFields("LastUpdateDate", DateTime.Now.ToString());
            return action.Update();
        }
        /// <summary>
        /// 发布话题
        /// </summary>
        /// <returns></returns>
        public int Add(DreamBox.Model.Posts m)
        {
            //
            DbProc gProc = new DbProc("dbox_proc_Posts");
            gProc.SetFields("@UserID",m.UserID);
            gProc.SetFields("@CID", m.CID);
            gProc.SetFields("@Title",m.Title);
            gProc.SetFields("@Contents",m.Contents);
            gProc.SetFields("@KeyWords", m.KeyWords != null && m.KeyWords != "" ? m.KeyWords : "");
            gProc.SetFields("@Thumbnail", m.Thumbnail);
            return int.Parse(gProc.ExecDataSet().Tables[0].Rows[0]["PostsID"].ToString());
        }
     
    }
}
